import request from "../utils/request.js";
import {encrypt} from "@/utils/jsencrypt.js";

export function getPage(currentPage,pageSize,select,state){
    return request({
        url: '/user',
        method: 'get',
        params: {
            currentPage,
            pageSize,
            'filterName':select,
            state
        }
    })
}

export function  getUser(userId){
    return request({
        url: '/user/' + userId,
        method: 'get',
    })
}
export function  getUserInfo(){
    return request({
        url: '/user/info',
        method: 'get',
    })
}
export function  addUser(user){
    return request({
        url: '/user',
        method: 'post',
        data: {
            ...user
        }
    })
}
export function  addUserAndRoles(user){
    return request({
        url: '/user/userRole',
        method: 'post',
        data: {
            ...user
        }
    })
}

export function  updateUser(user){
    return request({
        url: '/user',
        method: 'put',
        data: {
            ...user
        }
    })
}

export function  updateUserAndRoles(user){
    return request({
        url: '/user/userRole',
        method: 'put',
        data: {
            ...user
        }
    })
}

export function  deleteUsers(Ids){
    return request({
        url: '/user/' + Ids,
        method: 'delete',
    })
}

export function changePassword(data){
    data.oldPassword =  encrypt(data.oldPassword)
    data.newPassword = encrypt(data.newPassword)
    data.confirmPassword = encrypt(data.confirmPassword)
    return request({
        url: '/user/change',
        method: 'post',
        data: {
            ...data
        }
    })
}


